package com.ravi.service;

import com.ravi.dao.DoctorUserDAO;
import com.ravi.entity.DoctorUser;
import com.ravi.exception.CheckSystemException;
import com.ravi.exception.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class DoctorUserService {

	@Autowired
	private DoctorUserDAO doctorUserDAO;

	public DoctorUser login(DoctorUser user) {
		DoctorUser userDB = doctorUserDAO.findUserById(user.getWorkId());
		if (!ObjectUtils.isEmpty(userDB)) {
			if (userDB.getPassword().equals(user.getPassword())) {
				userDB.setPassword(null);
				return userDB;
			}else {
				throw new CheckSystemException("工号或密码错误！", ErrorCode.ID_OR_PASSWORD_ERROR);
			}
		}else {
			throw new CheckSystemException("工号或密码错误！", ErrorCode.ID_OR_PASSWORD_ERROR);
		}
	}
}
